<?php

/**
 * Class UrlManager
 * @author Brian Nguyen <thuann89@gmail.com>
 * @version 1.0
 * UrlManager is a property of webmaster, all right reserved.
 */
class UrlManager extends CUrlManager
{

    /**
     * @var string the class name or path alias for the URL rule instances. Defaults to 'CUrlRule'.
     */
    public $urlRuleClass = 'UrlRule';

    /**
     * Creates a URL rule instance.
     */
    public function createUrl($route, $params = array(), $ampersand = '&')
    {
        if (!isset($params['language']))
        {
            if (Yii::app()->user->hasState('language'))
            {
                Yii::app()->language = Yii::app()->user->getState('language');
            }
            else if (isset(Yii::app()->request->cookies['language']))
            {
                Yii::app()->language = Yii::app()->request->cookies['language']->value;
            }
            if (Yii::app()->language == 'en')
            {
                unset($params['language']);
            }
            else
                $params['language'] = Yii::app()->language;
        }
        return parent::createUrl($route, $params, $ampersand);
    }

}
